﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Globalization;

namespace Submarines
{
    public partial class frmWait : Form
    {
        Timer _timer = new Timer();
        int _max_val_for_timer;
        string _message;
        
        public bool Exist = false;
        public frmWait(int time_to_wait, string message)
        {
            InitializeComponent();
           _message = message;
           _max_val_for_timer = time_to_wait;
            Lang.Language(this, typeof(frmWait));
            if (!_timer.Enabled)
            {
                _timer.Tick += new EventHandler(_timer_Tick);
                _timer.Interval = 1000;
                _timer.Start();
            }
        }
        void _timer_Tick(object sender, EventArgs e)
        {
            if (_max_val_for_timer >= 0)
            {
                this.lblWait.Text = ((_max_val_for_timer--).ToString());
            }
            else
            {
                _timer.Stop();
                this.Close();
                string _mess1, _mess2;
                if (Global._Language == "Русский")
                {
                    _mess1 = "Нет ответа на ";
                    _mess2 = " запрос!";
                }
                else if (Global._Language == "עברית")
                {
                    _mess1 = "!";
                    _mess2 = " -" + "אין תשובה לבקשה";
                }
                else
                {
                    _mess1 = "No answer on ";
                    _mess2 = " request!";
                }
                Diag.AddLog(this.Name, _message);
                MessageBox.Show(_mess1 + "\"" + _message + "\"" + _mess2,"",MessageBoxButtons.OK,MessageBoxIcon.Warning);
            }
            
        }

        internal void CloseWindow()
        {
            _timer.Stop();
            _timer.Enabled = false;
            this.Close();
        }
    }
}
